

package com.hazelcast.sql.impl.client;

import com.hazelcast.internal.util.ExceptionUtil;
import com.hazelcast.sql.HazelcastSqlException;
import com.hazelcast.sql.impl.CoreQueryUtils;

import java.util.UUID;

/**
 * Static helpers for SQL client.
 */
public final class SqlClientUtils {

    private SqlClientUtils() {
        // No-op.
    }

    // Encode the exception as SqlError
    public static SqlError exceptionToClientError(Exception exception, UUID localMemberId) {
        HazelcastSqlException sqlException = CoreQueryUtils.toPublicException(exception, localMemberId);

        return new SqlError(sqlException.getCode(), sqlException.getMessage(), sqlException.getOriginatingMemberId(), sqlException.getSuggestion() != null, sqlException.getSuggestion(), true, ExceptionUtil.toString(exception));
    }
}
